/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.gluten.qt;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;

public class QualificationToolTest {
  private boolean areFileContentsSame(Path path1, Path path2) throws IOException {
    byte[] file1Bytes = Files.readAllBytes(path1);
    byte[] file2Bytes = Files.readAllBytes(path2);

    return Arrays.equals(file1Bytes, file2Bytes);
  }

  @Test
  public void testQualificationToolMain() throws IOException, URISyntaxException {
    String eventFilePath =
        new File(getClass().getResource("/event-files").getFile()).getAbsolutePath();

    Path outputPath = Files.createTempDirectory("output");

    String[] args =
        new String[] {"-f", eventFilePath, "-o", outputPath.toAbsolutePath().toString(), "-v"};

    org.apache.gluten.qt.QualificationTool.main(args);

    assert areFileContentsSame(
        outputPath.resolve("AppsRecommendedForBoost.tsv"),
        Paths.get(getClass().getResource("/AppsRecommendedForBoost.tsv").toURI()));
    assert areFileContentsSame(
        outputPath.resolve("UnsupportedOperators.tsv"),
        Paths.get(getClass().getResource("/UnsupportedOperators.tsv").toURI()));
  }
}
